package sqcon.sql;

import sqcon.util.StringParsingException;
import sqcon.util.StringTokenParser;

public class ComparisonNode extends ConditionTreeNode {
	
	private ComparisonOperator operator;
	private SQLComparable leftOperand;
	private SQLComparable rightOperand;
	
	public ComparisonNode(ComparisonOperator operator, 
			SQLComparable leftOperand, SQLComparable rightOperand){
		this.operator = operator;
		this.leftOperand = leftOperand;
		this.rightOperand = rightOperand;
	}

	@Override
	public boolean isLeaf(){
		return true;
	}
	
	@Override
	public String printString(){
		String leftOperandStr = leftOperand.printString();
		if(leftOperand.isQuery()){
			leftOperandStr = "(" + leftOperandStr + ")";
		}
		String rightOperandStr = rightOperand.printString();
		if(rightOperand.isQuery()){
			rightOperandStr = "(" + rightOperandStr + ")";
		}
		return leftOperandStr + " " 
			+ operator.printString() + " " 
			+ rightOperandStr;
	}
	
	public ComparisonOperator getOperator(){
		return operator;
	}
	
	public SQLComparable getLeftOperand(){
		return leftOperand;
	}
	
	public SQLComparable getRightOperand(){
		return rightOperand;
	}
	
	//TODO implement this method
	public static ComparisonNode generateComparisonNode(String compStr)
			throws ConstructSqlException{
		
		int pos = 0;
		int len = compStr.length();
		String leftOperand = "";
		String rightOperand = "";
		while(pos < len){
			
		}
		
		return null;
	}
}
